package com.logos.musicframe.config;

import com.logos.musicframe.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;


/**
 * @author logos
 * date 2025/5/29 12:51
 * @version v1.0
 * @Package com.logos.musicframe.config
 */
@Slf4j
@Configuration
public class AliOssConfig implements ApplicationListener<ContextRefreshedEvent> {

    @Bean
    @ConditionalOnMissingBean
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties) {
        log.info("开始上传阿里云文件上传工具类对象：{}", aliOssProperties);
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }

    private void refreshAliOssUtil() {
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        refreshAliOssUtil();
    }
}
